package com.suqiu.controller;

import com.suqiu.constant.RabbitConstant;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;

/**
 * @Description: rabbitmq测试
 * @Author: suqiu
 * @Date: 2022-02-15 14:43
 **/
@RestController
@RequestMapping("/rabbit")
public class RabbitTestController {

    @Resource
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/test")
    public String testRabbit() {
        MessageProperties messageProperties = new MessageProperties();
        messageProperties.setReplyTo(RabbitConstant.TOPIC_ROUTING_KEY_THREE);

        Message message = new Message("suqiu test rpc".getBytes(StandardCharsets.UTF_8), messageProperties);
        rabbitTemplate.send(RabbitConstant.TOPIC_MODE_QUEUE, RabbitConstant.TOPIC_ROUTING_KEY_TWO, message);
        return "success";
    }

}
